import axios from 'axios';
import qs from 'qs';
import {
    defaultUrl,
} from '../utils/consts/api.js';

axios.defaults.baseURL = defaultUrl;
axios.defaults.timeout = 2500;
axios.interceptors.request.use(function (config) {
    return config;
}, function (error) {
    console.log(error);
    return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {
    console.log(response);
    return response;
}, function (error) {
    console.log(error);
    return Promise.reject(error);
});


export const Post = function (url, data) {
    return axios.post(url, qs.stringify(data))
}

export const Get = function (url, data) {
    var parmas = `${url}?`;
    for (let key in data) {
        let value = data[key];
        parmas = `${key}=${value}&`;
    };
    parmas.replace(/&$/, "")
    return axios.get(url)
}